package com.oa.xinxi.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.oa.login.entity.Emp;
import com.oa.xinxi.biz.WorkZJBiz;
import com.oa.xinxi.entity.WorkZJ;

@Controller
@RequestMapping("/wzj")
public class WorkZJController {
	@Resource
	private WorkZJBiz workZJBiz;
	@RequestMapping("/list")
	public String list(Model model,@RequestParam(required=true,defaultValue="1") Integer page) {
		PageHelper.startPage(page, 10);
		List<WorkZJ> list = workZJBiz.findAll();
		PageInfo<WorkZJ> p=new PageInfo<WorkZJ>(list);
		model.addAttribute("list", list);
		model.addAttribute("page", p);
		return "/xinxi/wzj/list";
	}
	@RequestMapping("/preAdd")
	public String add() {
		return "/xinxi/wzj/add";
	}
	@RequestMapping("/add")
	public String save(WorkZJ workZJ,HttpSession session) {
//		System.out.println("添加");
		Emp emp = (Emp)session.getAttribute("emp");
		workZJ.setCreator(emp.getEmpName());
		workZJBiz.save(workZJ);
		return "redirect:/wzj/list";
	}
	@RequestMapping("/detail/{id}")
	public String detail(Model model,@PathVariable("id") int id) {
		WorkZJ workZJ = workZJBiz.findById(id);
		model.addAttribute("workZJ", workZJ);
		return "/xinxi/wzj/detail";
	}
	@RequestMapping("/delete/{id}")
	public String deleteById(Model model,@PathVariable("id") int id) {
		workZJBiz.deleteById(id);
		return "redirect:/wzj/list";
	}
	@RequestMapping("/preUpdate/{id}")
	public String updateById(Model model,@PathVariable("id") int id) {
		 WorkZJ workZJ = workZJBiz.findById(id);
		 model.addAttribute("workZJ", workZJ);
		return "/xinxi/wzj/update";
	}
	@RequestMapping("/update")
	public String DoUpdateById(WorkZJ workZJ,HttpSession session) {
//		System.out.println(news.getContent());
		Emp emp = (Emp)session.getAttribute("emp");
		workZJ.setUpdator(emp.getEmpName());
		workZJBiz.update(workZJ);
		return "redirect:/wzj/list";
	}
}
